#ifndef MOVEACTION_H
#define MOVEACTION_H

#include <QObject>
#include "tcpclient.h"
#include "machineparam.h"


/* 使用示例
    TcpClient *client = new TcpClient();
    client->connectToServer("192.168.2.103", 60000);
    MoveAction *action = new MoveAction();
    action->setTcpClient(client);
    action->powerOff();//发送指令
*/

//运动控制，通过tcp调用485模块

class MoveAction : public QObject
{
    Q_OBJECT
public:
    explicit MoveAction(QObject *parent = nullptr);

    //void  setTcpClient(TcpClient *client);

    bool powerOn();//开机
    bool powerOff();//关机

    bool moveAhead();//向前移动
    bool moveBack();//向后移动

private:

    QByteArray writMulti( unsigned char* pdu, int length);

public slots:
    void tryConnect(int id,QString ip, uint port);
    void onEmergency();
    void onConnectErr(QAbstractSocket::SocketError);

signals:
    void emitConnectResult(bool);

private:
    TcpClient *client;
};

#endif // MOVEACTION_H
